package com.example.musicwebcon.model;

import org.springframework.http.HttpStatus;

public class ResponseMessage<T> {
    private Integer code; //200  500  404
    private String message;
    private T data;

    public ResponseMessage(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseMessage() {

    }
    public static <T> ResponseMessage success() {
        return new ResponseMessage(200, "success", null);
    }
    // 失败响应
    public static <T> ResponseMessage error(String message) {
        return new ResponseMessage(500, message, null);
    }
    public static <T> ResponseMessage<T> success(T data){
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setCode(HttpStatus.OK.value()); //200
        responseMessage.setMessage("success!");
        responseMessage.setData(data);
        return responseMessage;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
